package com.vmj.rtda;

/**
 * Created by yangshoujun on 2017/8/12 上午11:51.
 */
public class Stack {

    int maxSize;
    int size;
    Frame top;
    java.util.Stack<Frame> stack;

    Stack(int maxSize) {
        this.maxSize = maxSize;
        stack = new java.util.Stack<Frame>();
    }

    public void pushFrame(Frame frame) {
        top = frame;
        stack.push(frame);
    }

    public Frame popFrame() {
        if(stack.isEmpty()) {
            throw new RuntimeException("jvm stack is empty");
        }
        Frame frame = stack.pop();
        if(stack.empty()) {
            top = null;
        } else {
            top = stack.peek();
        }
        return frame;
    }

    public Frame currentFrame() {
        if(stack.isEmpty()) {
            return null;
        }
        Frame frame = stack.peek();
        return frame;
    }

    public boolean isEmpty() {
        return 0 == stack.size();
    }

    public int getMaxSize() {
        return maxSize;
    }

    public int getSize() {
        return size;
    }

    public Frame getTop() {
        return top;
    }

    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public void setTop(Frame top) {
        this.top = top;
    }
}
